package com.sts.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.sts.bean.Car;
import com.sts.bean.User1;


@Repository
public class CarDap implements ICar {
	
	@Resource
	private SqlSessionFactory sqlSessionFactory;
	
	Logger log = Logger.getLogger(this.getClass());

	@Override
	public int insertCar(Car car) {
		log.debug("insertCar dao  in");
		
		SqlSession session = sqlSessionFactory.openSession();
		ICar iCar = session.getMapper(ICar.class) ;
		int result = iCar.insertCar(car) ;
				
		log.debug("insertCar dao  out");
		return result;
	}

	@Override
	public int deleteCar(String car_id) {
		log.debug("deleteCar dao  in");
		
		SqlSession session = sqlSessionFactory.openSession();
		ICar iCar = session.getMapper(ICar.class) ;
		int result = iCar.deleteCar(car_id) ;
				
		log.debug("deleteCar dao  out");
		return result;
	}

	@Override
	public List<Car> selectCar(Map<String, Object> map) {
		log.debug("selectCar dao  in");
		List<Car> list = new ArrayList<Car>() ;
		log.debug(map);
		SqlSession session = sqlSessionFactory.openSession();
		ICar iCar = session.getMapper(ICar.class) ;
		list = iCar.selectCar(map) ;
				
		log.debug("selectCar dao  out");
		return list;
	}

	@Override
	public int selSize(Map<String, Object> map) {
		log.debug("insertCar dao  in");
		log.debug(map);
		SqlSession session = sqlSessionFactory.openSession();
		ICar iCar = session.getMapper(ICar.class) ;
		int result = iCar.selSize(map) ;
				
		log.debug("insertCar dao  out");
		return result;
	}

	@Override
	public int updateCar(Car car) {
		log.debug("updateCar dao  in");
		
		SqlSession session = sqlSessionFactory.openSession();
		ICar iCar = session.getMapper(ICar.class) ;
		int result = iCar.updateCar(car) ;
				
		log.debug("updateCar dao  out");
		return result;
	}

}
